home *** CD-ROM | disk | FTP | other *** search
/ Reverse Code Engineering RCE CD +sandman 2000 / ReverseCodeEngineeringRceCdsandman2000.iso / RCE / Library / Manuels & Misc / Assembly / AOA.ZIP / CH13 / EX13_1C.ASM < prev    next >
Encoding:
Assembly Source File  |  1996-02-24  |  1.8 KB  |  95 lines

  1. ; EX13_1c.asm
  2. ;
  3. ; This program copies one file to another using the standard library
  4. ; file I/O routines.  The Standard Library file I/O routines let you do
  5. ; character at a time I/O, but they block up the data to transfer to improve
  6. ; system performance.  You should find that the execution time of this
  7. ; code is somewhere between blocked I/O (ex13_1b) and character at a time
  8. ; I/O (EX13_1a);  it will, however, be much closer to the block I/O time
  9. ; (probably about twice as long as block I/O).
  10.  
  11.         include     stdlib.a
  12.         includelib    stdlib.lib
  13.  
  14.  
  15. dseg        segment    para public 'data'
  16.  
  17. InFile        filevar    {}
  18. OutFile        filevar    {}
  19.  
  20. Filename    byte    "Ex13_1.in",0        ;Input file name
  21. Filename2    byte    "Ex13_1.out",0        ;Output file name
  22.  
  23. dseg        ends
  24.  
  25.  
  26. cseg        segment    para public 'code'
  27.         assume    cs:cseg, ds:dseg
  28.  
  29. Main        proc
  30.         mov    ax, dseg
  31.         mov    ds, ax
  32.         mov    es, ax
  33.         meminit
  34.  
  35. ; Open the input file:
  36.  
  37.         mov    ax, 0            ;Open for reading
  38.         ldxi    Filename
  39.         lesi    InFile
  40.         fopen
  41.         jc    BadOpen
  42.  
  43. ; Open the output file:
  44.  
  45.         mov    ax, 1            ;Open for output
  46.         ldxi    Filename2
  47.         lesi    OutFile
  48.         fcreate
  49.         jc    BadCreate
  50.  
  51. ; Copy the input file to the output file:
  52.  
  53. CopyLp:        lesi    InFile
  54.         fgetc
  55.         jc    GetDone
  56.  
  57.         lesi    OutFile
  58.         fputc
  59.         jmp    CopyLp
  60.  
  61. BadOpen:    printf
  62.         byte    "Error opening '%s'",cr,lf,0
  63.         dword    Filename
  64.         jmp    Quit
  65.  
  66. BadCreate:    printf
  67.         byte    "Error creating '%s'",cr,lf,0
  68.         dword    Filename2
  69.         jmp    CloseIn
  70.  
  71. GetDone:    cmp    ax, 0            ;Check for EOF
  72.         je    AtEOF
  73.  
  74.         print
  75.         byte    "Error copying files (read error)",cr,lf,0
  76.  
  77. AtEOF:        lesi    OutFile
  78.         fclose
  79. CloseIn:    lesi    InFile
  80.         fclose
  81.     
  82. Quit:        ExitPgm                ;DOS macro to quit program.
  83. Main        endp
  84.  
  85. cseg            ends
  86.  
  87. sseg        segment    para stack 'stack'
  88. stk        db    1024 dup ("stack   ")
  89. sseg        ends
  90.  
  91. zzzzzzseg    segment    para public 'zzzzzz'
  92. LastBytes    db    16 dup (?)
  93. zzzzzzseg    ends
  94.         end    Main
  95.